How to access Statistica Visual Basic Functions from Microsoft Excel ?

How to access Statistica Visual Basic Functions from Microsoft Excel ?

book

Article ID: KB0076397

calendar_today

Updated On:

Products Versions
Spotfire Statistica 13.3 and higher

Description

In this article, we will walk through an example that demonstrates how Statistica Visual Basic (SVB) code can be run from Visual basic within Excel.

Issue/Introduction

How to access Statistica Visual Basic (SVB) Functions from Microsoft Excel ?

Resolution

1. Launch Excel and then select press Alt+F11 to bring up the Visual Basic for Excel.
2.  Click on Tools >>References and add "STATISTICA Basic Statistics Library" and "STATISTICA Object Library"

User-added image

3. Double click on the Sheet name on the left pane to open the program editor. Add the below code for code. The lines that start with ' indicate a comment and offer explanation to what the function the code is performing.
 
 Sub ExcelTest() ' Run the STATISTICA application; create the STATISTICA ' Application object and assign it to variable (object) StatApp. Dim StatApp As New STATISTICA.Application ' Create a STATISTICA Basic Statistics object (i.e., run the ' Basic Statistics module; start it with data file exp ' (note: the actual location of that data file may be ' different on your installation). Dim s As Spreadsheet Set s = StatApp.Spreadsheets.Open(StatApp.Path & "\Examples\DataSets\Exp.sta") Dim BasStat As STATISTICA.Analysis Set BasStat = StatApp.Analysis(scBasicStatistics, s) ' the following 7 lines of code will produce a summary results ' Spreadsheet from the Statistica Basic Statistics module. BasStat.Dialog.Statistics = scBasDescriptives BasStat.Run BasStat.Dialog.Variables = "5-8" Dim out As STATISTICA.StaDocuments Set out = BasStat.Dialog.Summary ' Select all rows and columns in the Statistica results Spreadsheet. out.Item(1).SelectAll ' Copy the highlight selection (all rows and columns in the ' Summary results Spreadsheet. out.Item(1).Copy ' Set the cursor to cell A1 in the currently active Excel Spreadsheet. Range("A1").Select ' Paste in the summary statistics. ActiveSheet.PasteSpecial Format:="Biff4" s.Close End Sub

4. When you run this Visual Basic program from Microsoft Excel (via the Visual Basic Editor), it will paste the results from the Summary results spreadsheet of the Basic Statistics - Descriptive Statistics analysis into the current Excel Spreadsheet. Note that this is accomplished without the user ever seeing or having to interact with the Statistica application - the program runs entirely invisibly, and the results appear inside the Excel spreadsheet. This simple example illustrates the power and versatility of the Statistica Visual Basic object model. All analysis and graphics options and methods available in Statistica are fully exposed in the respective object libraries, and even advanced and complex analyses can be automated and performed routinely "behind the scenes" from within any other Visual Basic compatible application.

User-added image